//
//  BLTimeAxisRenderer.h
//  BLTimeAxis
//
//  Created by dg on 2025/4/18.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "BLTimeAxisVisitor.h"
#import "BLTimeAxisData.h"
#import "BLTimeAxisRule.h"
#import "BLTimeAxisDigitalDivision.h"
#import "BLTimeAxisBaseLine.h"
#import "BLTimeAxisBackground.h"

NS_ASSUME_NONNULL_BEGIN

@interface BLTimeAxisRenderer : NSObject <BLTimeAxisVisitor>

@property(nonatomic, assign) CGContextRef context;
@property(nonatomic, assign) CGSize viewSize;
@property(nonatomic, assign) CGFloat viewWidth;
@property(nonatomic, assign) CGFloat viewHeight;

- (instancetype)initWithViewSize:(CGSize)viewSize context:(CGContextRef)context;

@property (nonatomic, assign) NSTimeInterval minTimeInVisible;
@property (nonatomic, assign) NSTimeInterval maxTimeInVisible;

@property (nonatomic, strong) NSDate *currentHourDate;
@property (nonatomic, assign) NSInteger currentHour;
@property (nonatomic, assign) NSTimeInterval currentTimeInterval;

// 刻度尺在视图中的固定偏移位置
@property (nonatomic, assign) CGFloat ruleFixedOffset;

@property (nonatomic, assign) CGFloat baseLineFixedOffset;
@property (nonatomic, assign) CGFloat backgroundSize;

@property (nonatomic, assign) CGFloat aSecondOfPixel;
@property (nonatomic, assign) BLTimeAxisDirection axisDirection;

#pragma mark - 用于更新以上变量值
- (void)updateValueWithTimeAxisRule:(BLTimeAxisRule *)aTimeAxisRule;
- (void)updateValueWithTimeAxisBaseLine:(BLTimeAxisBaseLine *)aTimeAxisBaseLine;
- (void)updateValueWithTimeAxisDigitalDivision:(BLTimeAxisDigitalDivision *)aTimeAxisDigitalDivision;
- (void)updateValueWithTimeAxisBackground:(BLTimeAxisBackground *)aTimeAxisBackground;

#pragma mark - 辅助方法
- (void)drawLineWithContext:(CGContextRef)context from:(CGPoint)from to:(CGPoint)to;

/// 通用绘制方法
- (void)visitTimeAxis:(id<BLTimeAxisComponent>)aTimeAxis;

#pragma mark  子类需要重写的方法 且调用super
/// 绘制数据
- (void)visitTimeAxisData:(BLTimeAxisData *)aTimeAxisData;

/// 绘制刻度线
- (void)visitTimeAxisRule:(BLTimeAxisRule *)aTimeAxisRule;
/// 绘制基线
- (void)visitTimeAxisBaseLine:(BLTimeAxisBaseLine *)aTimeAxisBaseLine;
/// 绘制数字与分割线
- (void)visitTimeAxisDigitalDivision:(BLTimeAxisDigitalDivision *)aTimeAxisDigitalDivision;
/// 绘制背景
- (void)visitTimeAxisBackground:(BLTimeAxisBackground *)aTimeAxisBackground;

@end

NS_ASSUME_NONNULL_END
